<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>通过数据库升级模块</title>
  <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
  <link href="index.css" rel="stylesheet" type="text/css">
  <script th:src="@{/inc/common.js}"></script>
  <script th:src="@{/js/jquery-1.9.1.min.js}"></script>
  <script th:src="@{/js/jquery-migrate-1.2.1.min.js}"></script>
  <link rel="stylesheet" th:href="@{/js/bootstrap/css/bootstrap.min.css}"/>
  <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all">
  <script th:src="@{/js/bootstrap/js/bootstrap.min.js}"></script>
  <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
  <link th:href="@{/js/select2/select2.css}" rel="stylesheet"/>
  <script th:src="@{/js/select2/select2.js}"></script>
  <link th:href="@{/js/jquery-showLoading/showLoading.css}" rel="stylesheet" media="screen"/>
  <script type="text/javascript" th:src="@{/js/jquery-showLoading/jquery.showLoading.js}"></script>
  <script th:src="@{/js/jquery-alerts/jquery.alerts.js}" type="text/javascript"></script>
  <script th:src="@{/js/jquery-alerts/cws.alerts.js}" type="text/javascript"></script>
  <link th:href="@{/js/jquery-alerts/jquery.alerts.css}" rel="stylesheet" type="text/css" media="screen"/>
</head>
<!--<th:block th:if="${ifDbSource}">-->
<!--  <p th:text="${#messages.msg('err_id', errArgs)}"></p>-->
<!--</th:block>-->
<body>
<th:block th:if="${!ifDbSource}">
<table cellSpacing="0" cellPadding="3" width="95%" align="center" class="tabStyle_1">
  <tr>
    <td class="tabStyle_1_title" width="20%">编码</td>
    <td class="tabStyle_1_title" width="30%">新版</td>
    <td class="tabStyle_1_title" width="30%">本版</td>
    <td class="tabStyle_1_title" width="20%">操作</td>
  </tr>

  <tr th:each="co: ${codeInfo}">
    <td th:text="${co.codeNew}"></td>
    <td th:text="${co.nameNew}"></td>
    <th:block th:if="${co.isFound}">
      <td th:text="${co.name}"></td>
    </th:block>
    <td>
      <th:block th:if="${!co.isFound}">
        <button class="btn btn-default" th:onclick="sync('[(${formCode})]', '[(${co.code})]', '[(${co.nameNew})]', 'create')">创建</button>
      </th:block>
      <th:block th:unless="${!co.isFound}">
        <button class="btn btn-default" th:onclick="sync('[(${formCode})]', '[(${co.codeNew})]', '[(${co.nameNew})]', 'edit')">同步</button>
      </th:block>
    </td>
  </tr>
</table>
</th:block>
</body>
<script>
  function sync(formCode, moduleCode, name, action) {
    layer.confirm('您确定要同步"' + name + '"么？', {icon: 3, title: '提示'}, function (r) {
      layer.close();

      if (!r) {
        return;
      }

      $.ajax({
        type: "post",
        url: "upgradeModuleByDbBtn",
        data: {
          op: "syncModule",
          formCode: formCode,
          moduleCode: moduleCode,
          dbSource: '[[${dbSource}]]',
          action: action
        },
        dataType: "html",
        beforeSend: function (XMLHttpRequest) {
          $("body").showLoading();
        },
        success: function (data, status) {
          data = $.parseJSON(data);
          layer.msg(data.msg,  {
            // window.location.reload();
          });
        },
        complete: function (XMLHttpRequest, status) {
          $("body").hideLoading();
        },
        error: function (XMLHttpRequest, textStatus) {
          // 请求出错处理
          alert(XMLHttpRequest.responseText);
        }
      });
    });
  }
</script>
</html>
